const app = getApp();
Page({
  data: {
    data: {}
  },
  onLoad: function (options) {
    this.setData({
      code:options.code,
      securityCode: options.securityCode
    })
  },
  toNext: function (e) {
    console.log(e.detail.value);
    this.setNewlogin(e)
  },
  //登录密码
  setNewlogin:function(e){
    const _this = this;
    if (e.detail.value.pwd2 != '' && e.detail.value.testPwd != ''){
      if (e.detail.value.pwd2.length >= 6 && e.detail.value.pwd2.length <= 18){
        if (e.detail.value.pwd2 === e.detail.value.testPwd) {
          wx.request({
            url: app.globalData.path + 'services/app/applets/MofityPassWord',
            data: {
              oldPassword: e.detail.value.pwd1,
              newPassword: e.detail.value.pwd2
            },
            method: 'POST',
            header: {
              'content-type': 'application/json', // 默认值
              'Authorization': 'Bearer ' + app.globalData.authorization
            },
            success: function (res) {
              console.log(res.data);
              if (res.data.success) {
                console.log('修改成功')
                wx.showToast({
                  title: '修改成功',
                  icon: 'success',
                  duration: 2000
                })
                wx.removeStorage({
                  key: 'token',
                  success: function (res) {
                  },
                })
                wx.reLaunch({
                  url: '../login/login'
                })
              } else {
                wx.showToast({
                  title: res.data.error.message,
                  icon: 'none',
                  duration: 2000
                })
              }
            }
          })
        } else {
          wx.showModal({
            content: '两次密码不同',
            showCancel: false,
            success: function (res) {
              if (res.confirm) {
                // console.log('用户点击确定')
              }
            }
          });
        }
      }else{
        wx.showModal({
          content: '密码格式不对，要求6~18位',
          showCancel: false,
          success: function (res) {
            if (res.confirm) {
              // console.log('用户点击确定')
            }
          }
        });
      }
    }else{
      wx.showModal({
        content: '密码不能为空',
        showCancel: false,
        success: function (res) {
          if (res.confirm) {
            // console.log('用户点击确定')
          }
        }
      });
    }
  },
})